<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="vue.js"></script>
</head>
<body>
	<div id="root">
		<counter ref="one" @change="handleChange"></counter>
		<counter ref="two" @change="handleChange"></counter>
		<div>{{count}}</div>
	</div>
	
	<script>

		Vue.component('counter',{
			template: '<div @click="handleClick">{{count}}</div>',
			data () {
				return {
					count: 0
				}
			},
			methods: {
				handleClick () {
					this.count++;
					this.$emit('change');
				}
			}
		})

		var vm = new Vue({
			el: '#root',
			data: {
				count: 0
			},
			methods: {
				handleChange () {
					this.count = this.$refs.one.count + this.$refs.two.count;
				}
			}
		})
	</script>
</body>
</html>